//
//  LXPermissionPhoto.swift
//  LXPermissionAuth
//
//  Created by yoctech on 2021/8/18.
//

import UIKit
import Photos

@objc class LXPermissionPhoto: NSObject, LXPermissionProtocol {
    @objc public static func auth(autoRequestIfNot: Bool, clouser: @escaping LXAuthClouser) {
        let aStatus = PHPhotoLibrary.authorizationStatus()
        switch aStatus {
        case .notDetermined:
            if autoRequestIfNot {
                DispatchQueue.main.async {
                    PHPhotoLibrary.requestAuthorization { (status) in
                        if status == .authorized{
                            clouser(true, .authorized)
                        }else{
                            clouser(false, .other)
                        }
                    }
                }
            }else {
                clouser(false, .notDetermined)
            }
        case .denied:
            clouser(false, .denied)
        case .restricted:
            clouser(false, .restricted)
        case .authorized:
            clouser(true, .authorized)
        case .limited:
            clouser(true, .authorized)
        @unknown default:
            clouser(false, .other)
        }
    }
    

}
